from datetime import datetime
from mcp.server.fastmcp import FastMCP


mcp = FastMCP("My App")


@mcp.tool()
def get_weekday_from_date(date_str: str) -> str:
    '''
    input date, return weekday
    :param date_str: the string of date, format is YYYY-MM-DD
    :return: the weekday
    '''
    try:
        date = datetime.strptime(date_str, '%Y-%m-%d')
        weekday_number = date.weekday()
        weekdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
        return weekdays[weekday_number]
    except ValueError:
        return "invalid date, use YYYY-MM-DD format."

if __name__ == "__main__":
    mcp.run(transport="stdio")